<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    let obj = {};

    //为 obj 添加 name 属性
    // obj.name = 'xxx';
    //通过变量实现
    // let key = 'name';
    // obj[key] = 'xxx';

    //声明变量
    let key = 'name';
    let obj2 = {
      // name: 'xxx'
      [key]: 'xxx'
    };

    console.log(obj2);
    

  </script>
</body>
</html>